<?php
namespace app\index\controller;

use app\index\base_controller\BaseController;
use app\index\model\RoomUseModel;
use app\index\model\TestModel;
use app\index\model\UnitDepartModel;
use app\index\table\BookTable;
use app\index\table\BuildingTable;
use app\index\table\CarTable;
use app\index\table\ConstructionTable;
use app\index\table\FacilityTable;
use app\index\table\FurnTable;
use app\index\table\IntangibleTable;
use app\index\table\InvestTable;
use app\index\table\LandTable;
use app\index\table\LiquidTable;
use think\Controller;
use think\Db;
use app\index\model\RoomModel;
use think\Session;

class Index extends BaseController
{

    public function test2(){
        return view('test');
    }

    public function index2(){
        return view('index2');
    }

    public function index()
    {
        $facilityCount = FacilityTable::table()->count();
        $furnCount = FurnTable::table()->count();
        $bookCount = BookTable::table()->count();
        $landCount = LandTable::table()->count();
        $buildingCount = BuildingTable::table()->count();

        $list = [
            [
                'icon'=>'fa fa-laptop fa-4x'
                ,'title'=>'设备管理'
                ,'count'=>$facilityCount
                ,'url'=>url('index/facility/facilityList')
            ]
            ,[
                'icon'=>'fa fa-suitcase fa-4x'
                ,'title'=>'家具管理'
                ,'count'=>$furnCount
                ,'url'=>url('index/furn/furnList')
            ]
            ,[
                'icon'=>'fa fa-book fa-4x'
                ,'title'=>'图书管理'
                ,'count'=>$bookCount
                ,'url'=>url('index/book/bookList')
            ]
            ,[
                'icon'=>'fa fa-road fa-4x'
                ,'title'=>'土地管理'
                ,'count'=>$landCount
                ,'url'=>url('index/land/landList')
            ]
            ,[
                'icon'=>'fa fa-home fa-4x'
                ,'title'=>'房屋构筑物'
                ,'count'=>$buildingCount
                ,'url'=>url('index/building/buildingList')
            ]
            ,[
                'icon'=>'fa fa-stack-overflow fa-4x'
                ,'title'=>'流动资产'
                ,'count'=>LiquidTable::table()->count()
                ,'url'=>url('index/liquid/liquidList')
            ]
            ,[
                'icon'=>'fa fa-tasks fa-4x'
                ,'title'=>'无形资产'
                ,'count'=>IntangibleTable::table()->count()
                ,'url'=>url('index/intangible/intangibleList')
            ]
            ,[
                'icon'=>'fa fa-globe fa-4x'
                ,'title'=>'对外投资'
                ,'count'=>InvestTable::table()->count()
                ,'url'=>url('index/invest/investList')
            ]
            ,[
                'icon'=>'fa fa-building-o fa-4x'
                ,'title'=>'在建工程'
                ,'count'=>ConstructionTable::table()->count()
                ,'url'=>url('index/constuction/constuctionList')
            ]
            ,[
                'icon'=>'fa fa-car fa-4x'
                ,'title'=>'车辆管理'
                ,'count'=>CarTable::table()->count()
                ,'url'=>url('index/car/carList')
            ]
        ];

        $this->assign('list',$list);
        return $this->fetch('index');
    }

    public function edit()
    {
        return $this->fetch('edit');
    }

    function msectime() {
        list($msec, $sec) = explode(' ', microtime());
        $msectime =  (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        return $msectime;
    }

//    public function setRoomUse(){
//
//        Db::startTrans();
//        $roomList = RoomModel::all();
//        foreach ($roomList as $room){
//            unset($roomUse);
//            $roomUse = new RoomUseModel();
//            $roomUse->ROOM_ID = $room['RM_SNO'];
//            $roomUse->UD1 = $room['UD_SNO'];
//            $roomUse->UD2 = $room['UD_SNO2'];
//            $roomUse->UD3 = $room['UD_SNO3'];
//            $roomUse->UD_OFFICE = $room['UD_OFFICE'];
//            $roomUse->RESPONSIBLE_PERSON = $room['EMP_SNAME'];
//            $roomUse->RESPONSIBLE_PHONE = $room['EMP_STEL'];
//            $roomUse->USE_PERSON_LIST = $room['EMP_SNO1'];
//            $roomUse->KEY_NUMBER = $room['RM_SKEYNO'];
//            $roomUse->ROOM_NATURE = $room['RN_SNO'];
//            $roomUse->USE_REMARK = $room['USE_REMARK'];
//            $roomUse->COURSE_NAME = $room['COURSE_NAME'];
//            $roomUse->COURSE_PEOPLE_COUNT = $room['COURSE_PEOPLE_COUNT'];
//            $roomUse->COURSE_HOURS = $room['COURSE_HOURS'];
//            $roomUse->IS_LONG_USE = '1';
//            $roomUse->STATUS = $room['RM_SSTATE'];
//            $roomUse->UPDATE_TIME = date('Y-m-d H:i:s');
//            $roomUse->UPDATE_USER_ID = Session::get('userId');
//            $roomUse->UPDATE_TYPE = 'excel导入';
//            $roomUse->save();
//
//            $room->ROOM_USE_ID = $roomUse->ROOM_USE_ID;
//            $room->save();
//        }
//        Db::commit();
//        echo '操作成功';
//    }

    public function index3(){
        $room = RoomModel::with('roomUse')->find(1);
        return json_encode($room);
    }

}
